class GameUI extends egret.Sprite {

    public constructor() {
        super();
        // this.createView();
        this.once(egret.Event.ADDED_TO_STAGE, this.createView, this);
    }
    private curIndex = 0;               //当前的礼物索引
    private frameTime;              //计算每帧运行时间
    private countdownMaxNumber = 5;//默认倒计时最大秒数
    private countdownCurNumber;//当前的倒计时的秒数
    private countdownSprite;  //倒计时显示对象
    private scoreSprite;      //分数显示对象
    private giftArr;          //物品数组，里面装载了礼物和炸弹对象，并说明添加的分数
    private adLogo;           //点击礼物出现logo对象
    private timer;          //礼物定时器
    private gameStatus = 1; //表示游戏状态   0游戏结束    1游戏开始
    private score = 0;      //玩家游戏分数
    private scoreText;        //分数文本
    private roundRect;      //椭圆框
    private time;           //验证码定时器
    private target;
    private allGift = [];
    private createView(): void {
        //计算一下每帧运行时间
        this.frameTime = 1 / this.$stage.frameRate;// 1/60≈16.66
        //初始化一下当前倒计时秒数为最大倒计时秒数
        this.countdownCurNumber = this.countdownMaxNumber;
        //添加背景
        var bg = createBitmap("bg_jpg");
        this.addChild(bg);
        //雪花
        var snowflake1_1 = createBitmap("one_snowflower_png", 0, 0);
        var snowflake2_2 = createBitmap("one_snowflower_png", 0, -1206);
        egret.Tween.get(snowflake1_1, { loop: true }).to({ y: 1206 }, 10000);
        egret.Tween.get(snowflake2_2, { loop: true }).to({ y: 0 }, 10000);
        this.addChild(snowflake1_1);
        this.addChild(snowflake2_2);

        //添加倒计时文本
        var countdownText = createTextFiled("倒计时", 267, 15, 18, 0xffffff);
        this.addChild(countdownText);

        //添加倒计时
        this.countdownSprite = createTextFiled(this.countdownMaxNumber.toString(), 0, 36, 48, 0xffffff, "center", 750);
        this.addChild(this.countdownSprite);

        //圆角矩形
        this.roundRect = new egret.Shape();
        this.roundRect.graphics.lineStyle(2, 0xffffff);
        this.roundRect.graphics.drawRoundRect(516, 26, 222, 55, 55, 55);
        this.roundRect.graphics.endFill();
        this.addChild(this.roundRect);

        //添加分数文本
        this.scoreText = createTextFiled("分数 : ", 535, 40, 28, 0xffffff);
        this.addChild(this.scoreText);

        //添加分数
        this.scoreSprite = createTextFiled("0000", 600, 40, 28, 0xffffff, "right", 110);
        this.addChild(this.scoreSprite);

        //初始化物品数组
        this.giftArr = [];
        var self = this;
        var addscore;   //点击显示分数
        for (var i = 1; i <= 10; i++) {
            var bitmap = createBitmap("gift" + i + "_png");
            bitmap.x = 375;
            bitmap.y = 1350;
            bitmap.anchorOffsetX = bitmap.width * .5;
            bitmap.anchorOffsetY = bitmap.height * .5;
            bitmap.alpha = .4;
            bitmap.scaleX = .4;
            bitmap.scaleY = .4;
            this.allGift.push(bitmap);
            bitmap.addEventListener(egret.TouchEvent.TOUCH_TAP, function (e) {
                var index = Math.ceil(Math.random() * 10 + 1);
                egret.Tween.get(this).to({ scaleX: 0, scaleY: 0 }, 250).call(function () {
                    var showTime = index == 11 ? 2000 : 300;
                    this.adLogo.texture = RES.getRes("logo" + index + "_png");
                    this.adLogo.anchorOffsetX = this.adLogo.width * .5;
                    this.adLogo.anchorOffsetY = this.adLogo.height * .5;
                    this.adLogo.x = e.stageX;
                    this.adLogo.y = e.stageY;
                    this.adLogo.scaleX = 0;
                    this.adLogo.scaleY = 0;
                    egret.Tween.get(this.adLogo).to({ scaleX: 3, scaleY: 3 }, 1000).to({ scaleX: 0, scaleY: 0 }, 300)
                }.bind(self));
                this.touchEnabled = false;

                //获取点击物所对应的属性
                var data;
                for (var k in self.giftArr) {
                    if (self.giftArr[k].bitmap == this) {
                        data = self.giftArr[k];
                    }
                }

                //加减分数
                if (data["isGift"]) {
                    self.score += data["score"];
                    addscore = createTextFiled("+" + data["score"], e.stageX, e.stageY - 30, 50, 0Xffcc00);//显示加的分
                } else {
                    self.score -= data["score"];
                    addscore = createTextFiled("-" + data["score"], e.stageX, e.stageY - 30, 50, 0Xffcc00);//显示减的分
                }
                self.addChild(addscore);
                self.score = self.score <= 0 ? 0 : self.score;
                egret.Tween.get(addscore).to({ scaleX: 0, scaleY: 0 }, 2000);

                //把分数同步更新到显示对象
                self.scoreSprite.text = self.score;
            }, bitmap);
            this.addChild(bitmap);
            var tmpJson = {
                "bitmap": bitmap,
                "score": i * 100,
                "isGift": i > 8 ? false : true
            };
            this.giftArr.push(tmpJson);
        }


        //添加地板
        var floor = createBitmap("bottom_bg_png", 0, 957);
        this.addChild(floor);

        //广告logo
        this.adLogo = createBitmap("");
        this.addChild(this.adLogo);

        //游戏主循环，可以给当前场景添加一个“进入帧”事件，则可以根据我们当初所制定的帧频来控制游戏速度。每一帧的渲染速度就是  1s/60帧 = 16.6666s
        this.addEventListener(egret.Event.ENTER_FRAME, this.loop, this);

        //创建一个定时器
        this.timer = new egret.Timer(1000, 0);
        this.timer.addEventListener(egret.TimerEvent.TIMER, this.giftLoop, this);
        this.timer.start();
        
    }

    private giftLoop() {
        var target = this.giftArr[this.curIndex];
        this.target=target;
        egret.Tween.get(target.bitmap)
            .to({ y: -100 }, 300).call(function () {
                target.bitmap.alpha = 1;
                target.bitmap.x = Math.random() * 650 + 50;//随机范围控制:随机数*(最大值-最小值)+最小值
                target.bitmap.scaleX = 1;
                target.bitmap.scaleY = 1;
                target.bitmap.touchEnabled = true;
                this.setChildIndex(target.bitmap, this.numChildren - 1);
            }.bind(this))  //向上飞
            .to({ y: 1350 }, 2500).call(function () {
                target.bitmap.alpha = .4;
                target.bitmap.x = 375;
                target.bitmap.scaleX = .6;
                target.bitmap.scaleY = .6;
                target.bitmap.touchEnabled = false;
                this.setChildIndex(target.bitmap, 9);
            }.bind(this));   //向下掉

        this.curIndex++;
        if (this.curIndex >= 10) {
            this.curIndex = 0;
        }
        
    }

    private loop() {
        console.log(this.$stage.frameRate);
        //抽奖弹窗
        var explain = div(0, 0, 750, 0, 750, 1206, 0, 1206, 0, 0, 0, 0);
        this.addChild(explain)
        var explainbg = createBitmap("1212_png", 16, 158);
        explain.addChild(explainbg);
        //左眼
        var eye1 = new egret.Shape();
        eye1.graphics.beginFill(0x000000);
        eye1.graphics.drawCircle(273, 298, 5);
        egret.Tween.get(eye1, { loop: true }).to({ x: 0 }, 1000).to({ x: 8 }, 1000).to({ x: 0 }, 1000);
        eye1.graphics.endFill();
        explain.addChild(eye1);
        //有眼
        var eye2 = new egret.Shape();
        eye2.graphics.beginFill(0x000000);
        eye2.graphics.drawCircle(345, 298, 5);
        egret.Tween.get(eye2, { loop: true }).to({ x: 0 }, 1000).to({ x: 8 }, 1000).to({ x: 0 }, 1000);
        eye2.graphics.endFill();
        explain.addChild(eye2);

        //游戏结束
        var gameover = div(87, 503, 665, 503, 665, 995, 87, 995, 87, 503, 87, 503);
        explain.addChild(gameover);

        var good = createTextFiled("厉害了！", 50, 40, 30, 0x3d9c30);
        gameover.addChild(good);

        var fraction = createTextFiled("你获得了" + this.score + "分！", 89, 100, 48, 0x3d9c30);
        gameover.addChild(fraction);

        var xian1 = drawReactShape(null, 290, 145, 22, 4, 0x3d9c30, 0x3d9c30);
        gameover.addChild(xian1);

        var xian2 = drawReactShape(null, 320, 145, 22, 4, 0x3d9c30, 0x3d9c30);
        gameover.addChild(xian2);

        var xian3 = drawReactShape(null, 350, 145, 22, 4, 0x3d9c30, 0x3d9c30);
        gameover.addChild(xian3);

        var guideagain = createTextFiled("选择“抽奖”可进行抽奖", 50, 245, 34, 0xff508a, "feft", 480);
        guideagain.lineSpacing = 30;
        gameover.addChild(guideagain);

        var guideshare = createTextFiled("选择“分享好友”可获得现金豪礼哦", 50, 313, 30, 0x4085ff);
        gameover.addChild(guideshare);



        //厉害了大兄弟页抽奖按钮
        var choujiang_btn = createBitmap("win_noneBtnpink_png", 200, 380);
        gameover.addChild(choujiang_btn);
        choujiang_btn.touchEnabled = true;
        choujiang_btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            // SenceManage.create(this.stage).loadSence("HomePageUI", this, HomePageUI);
                        egret.Tween.get(this).to({x:-640},500);
            
            choujiang_btn.touchEnabled = false;
        }, this);

        var choujiang_wenben = createTextFiled("抽奖", 270, 395, 38, 0xffffff);
        gameover.addChild(choujiang_wenben);

        //得分超过的分享
        var fenxiang1 = createBitmap("fenxiang_03_jpg", 319, 308,);
        fenxiang1.touchEnabled = false;
        fenxiang1.visible = false;
        fenxiang1.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            // SenceManage.create(this.stage).loadSence("HomePageUI", this, HomePageUI);
            
            choujiang_btn.touchEnabled = false;
        }, this);
        gameover.addChild(fenxiang1);

        explain.visible = false;//隐藏抽奖页
        //超过分数分享监听事件
        fenxiang1.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            egret.Tween.get(person).to({ scaleX: 1, scaleY: 1 }, 1000).call(function () { })
            person.visible = true;
            gameover.visible = false
        }, this);

        //继续游戏弹窗
        var again = div(0, 0, 750, 0, 750, 1206, 0, 1206, 0, 0, 0, 0);
        this.addChild(again)
        var explainbg = createBitmap("1212_png", 16, 158);
        again.addChild(explainbg);
        //左眼    
        var eye1 = new egret.Shape();
        eye1.graphics.beginFill(0x000000);
        eye1.graphics.drawCircle(273, 298, 5);
        egret.Tween.get(eye1, { loop: true }).to({ x: 0 }, 1000).to({ x: 8 }, 1000).to({ x: 0 }, 1000).to({ x: 8 }, 1000);
        eye1.graphics.endFill();
        again.addChild(eye1);

        //右眼
        var eye2 = new egret.Shape();
        eye2.graphics.beginFill(0x000000);
        eye2.graphics.drawCircle(345, 298, 5);
        egret.Tween.get(eye2, { loop: true }).to({ x: 0 }, 1000).to({ x: 8 }, 1000).to({ x: 0 }, 1000).to({ x: 8 }, 1000);
        eye2.graphics.endFill();
        again.addChild(eye2);

        var gameover = div(87, 503, 665, 503, 665, 995, 87, 995, 87, 503, 87, 503);
        again.addChild(gameover);

        var good = createTextFiled("厉害了喔！", 50, 40, 30, 0x3d9c30);
        gameover.addChild(good);

        var fraction = createTextFiled("你获得了" + this.score + " 分！", 89, 100, 48, 0x3d9c30);
        gameover.addChild(fraction);

        var xian1 = drawReactShape(null, 290, 145, 22, 4, 0x3d9c30, 0x3d9c30);
        gameover.addChild(xian1);

        var xian2 = drawReactShape(null, 320, 145, 22, 4, 0x3d9c30, 0x3d9c30);
        gameover.addChild(xian2);

        var xian3 = drawReactShape(null, 350, 145, 22, 4, 0x3d9c30, 0x3d9c30);
        gameover.addChild(xian3);

        var guideagain = createTextFiled("选择“继续游戏”可再次进入游戏累计满1000分即可抽奖", 50, 195, 34, 0xff508a, "feft", 480);
        guideagain.lineSpacing = 30;
        gameover.addChild(guideagain);

        var guideshare = createTextFiled("选择“分享好友”可获得现金豪礼", 50, 313, 30, 0x4085ff);
        gameover.addChild(guideshare);

        var again_btn = createBitmap("aging_btn_png", 50, 380, );
        gameover.addChild(again_btn);
        again_btn.touchEnabled = true;
        again_btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            SenceManage.create(this.stage).loadSence("GameUI", null, GameUI);
                        egret.Tween.get(this).to({x:-640},500);

            again_btn.touchEnabled = false;
        }, this);

        // 小于分享
        var fenxiang = createBitmap("fenxiang_03_jpg", 319, 378);
        gameover.addChild(fenxiang);
        fenxiang.touchEnabled = true;
        fenxiang.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            game_over.visible = true;
            again_btn.touchEnabled = false;
            eye1.visible = false;
            eye2.visible = false;
            explainbg.visible = false;
            this.scoreSprite.visible = false;
            this.roundRect.visible = false;
            this.scoreText.visible = false;
        }, this)
        again.visible = false;//隐藏继续游戏页


        // ZHENJIAN 留资页
        //留资页一
        var person = div(20, 120, 736, 120, 736, 1172, 20, 1172, 20, 120, 20, 120);
        this.addChild(person)
        person.visible =false;
        //留资页1
        var personBG = createBitmap("1212_png", -3, 37);
        person.addChild(personBG)
        //左眼
        var personBGEye1 = new egret.Shape();
        personBGEye1.graphics.beginFill(0x000000);
        personBGEye1.graphics.drawCircle(260, 170, 5);
        egret.Tween.get(personBGEye1, { loop: true }).to({ x: 0 }, 1000).to({ x: 8 }, 1000).to({ x: 0 }, 1000);
        personBGEye1.graphics.endFill();
        person.addChild(personBGEye1);
        //右眼
        var personBGEye2 = new egret.Shape();
        personBGEye2.graphics.beginFill(0x000000);
        personBGEye2.graphics.drawCircle(322, 170, 5);
        egret.Tween.get(personBGEye2, { loop: true }).to({ x: 0 }, 1000).to({ x: 8 }, 1000).to({ x: 0 }, 1000);
        personBGEye2.graphics.endFill();
        person.addChild(personBGEye2);
        //留资页姓名
        var name1 = createTextFiled("姓名 ：", 88, 470, 36, 0x54734a)
        person.addChild(name1);
        var name2 = createTextFiled("电话 ：", 88, 565, 36, 0x54734a)
        person.addChild(name2);
        var name3 = createTextFiled("验证码 ：", 88, 660, 36, 0x54734a)
        person.addChild(name3);
        //input
        var input1 = createTextFiled("", 228, 454, 36, 0x54734a, "", 426, 66, "middle", false, 0xa0a0a0, true, "INPUT")
        input1.type = egret.TextFieldType.INPUT;
        person.addChild(input1);
        var input2 = createTextFiled("", 228, 550, 36, 0x54734a, "", 285, 66, "middle", false, 0xa0a0a0, true, "INPUT")
        input2.type = egret.TextFieldType.INPUT;


        person.addChild(input2);
        var input3 = createTextFiled("", 255, 645, 36, 0x54734a, "", 400, 66, "middle", false, 0xa0a0a0, true, "INPUT")
        input3.type = egret.TextFieldType.INPUT;
        person.addChild(input3);
        //input_border
        var input_border = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(208, 454, 426, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border.addChild(roundRect);
        person.addChild(input_border);
        //
        var input_border2 = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(208, 550, 285, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border2.addChild(roundRect);
        person.addChild(input_border2);
        //
        var input_border3 = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(235, 645, 400, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border3.addChild(roundRect);
        person.addChild(input_border3);

        //新验证码倒计时功能
        //验证码倒计时
        var input_border4 = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.beginFill(0x789798);
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(505, 550, 120, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border4.addChild(roundRect);
        person.addChild(input_border4);
        //
        var yanzhen1 = createTextFiled("", 520, 560, 25, 0x000000)
        yanzhen1.text = "获取验";
        input_border4.addChild(yanzhen1);
        var yanzhen2 = createTextFiled("", 535, 590, 25, 0x000000)
        yanzhen2.text = "证码_";
        input_border4.addChild(yanzhen2);
        input_border4.touchEnabled = true
        input_border4.once(egret.TouchEvent.TOUCH_TAP, function (
        ) {

            input_border4.touchEnabled = false
            var time2 = 60
            var time1 = setInterval(function () {
                // console.log(111)
                //   alert(223) 

                yanzhen1.text = "倒计时 :";
                time2 -= 1;
                yanzhen2.text = time2 + " S";
                //   alert(222) 
                if (time2 < 1) {
                    var roundRect = new egret.Shape();
                    roundRect.graphics.beginFill(0x7b7b7b)
                    roundRect.graphics.lineStyle(2, 0xa0a0a0);
                    roundRect.graphics.drawRoundRect(505, 550, 120, 66, 30, 30);
                    roundRect.graphics.endFill();
                    input_border4.addChild(roundRect);
                    yanzhen1.text = "获取验";
                    input_border4.addChild(yanzhen1);
                    yanzhen2.text = "证码";
                    input_border4.addChild(yanzhen2);
                    input_border4.touchEnabled = true
                    time2 = 60
                    clearInterval(time1);
                }
            }, 1000)
            var roundRect = new egret.Shape();
            roundRect.graphics.beginFill(0x789798)
            roundRect.graphics.lineStyle(2, 0xa0a0a0);
            roundRect.graphics.drawRoundRect(505, 550, 120, 66, 30, 30);
            roundRect.graphics.endFill();
            input_border4.addChild(roundRect);
        }, this)


        // 新验证码倒计时功能结束

        //验证码倒计时
        // var input_border4 = new egret.DisplayObjectContainer();
        // var roundRect = new egret.Shape();
        // roundRect.graphics.beginFill(0x7b7b7b);
        // roundRect.graphics.lineStyle(2, 0xa0a0a0);
        // roundRect.graphics.drawRoundRect(505, 550, 120, 66, 30, 30);
        // roundRect.graphics.endFill();
        // input_border4.addChild(roundRect);
        // person.addChild(input_border4);

        // //
        // var yanzhenT = createTextFiled("倒计时 ：", 515, 560, 25, 0x000000);
        // yanzhenT.visible = false;
        // input_border4.addChild(yanzhenT);
        // var yanzhenN = createTextFiled("60S ", 535, 590, 25, 0x000000);
        // yanzhenN.visible = false;
        // input_border4.addChild(yanzhenN);


        // //获取验证码按钮
        // var getCode = createTextFiled("点击获取\n验证码", 515, 560, 25, 0xff0000);
        // getCode.touchEnabled = true;
        // getCode.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
        //     getCode.touchEnabled = false;
        //     getCode.visible = false;
        //     yanzhenT.visible = true;
        //     yanzhenN.visible = true;
        // }, this)
        // input_border4.addChild(getCode);


        //分享后大于指定分数时候点击抽奖按钮
        var choujiang_btnDayu = createBitmap("four_btnpink_png", 260, 894);
        person.addChild(choujiang_btnDayu)
        var choudajiang = createTextFiled("抽奖", 328, 910, 36, 0xfffffff);
        choudajiang.touchEnabled = true;
        choudajiang.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            // alert(666)
            SenceManage.create(this.stage).loadSence("HomePageUI", null, HomePageUI);
            person.visible = false;
        }, this)
        person.addChild(choudajiang);
        // person.visible = false;
        // 暂时隐藏资料一
        // this.removeChild(person)
        //  fenxiang.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
        //     explain.visible = false
        //     person.visible  =true
        // }, this);
        //留资页二
        var person2 = div(0, 0, 750, 0, 750, 1206, 750, 0, 1206, 0, 0, 0);
        this.addChild(person2)
        //留资页二
        var personBG2 = createBitmap("liuzi2_1_png", 18, 342);
        person2.addChild(personBG2)
        var fenxiang = createBitmap("seven_share_png", 530, 34);
        person2.addChild(fenxiang)
        //
        var person_title = createBitmap("liuzi_tiitle_png", 85, 222);
        person2.addChild(person_title)
        var name1_1 = createTextFiled("姓名 ：", 104, 630, 36, 0x54734a)
        person2.addChild(name1_1);
        var name2_2 = createTextFiled("电话 ：", 104, 725, 36, 0x54734a)
        person2.addChild(name2_2);
        var name3_3 = createTextFiled("验证码 ：", 104, 820, 36, 0x54734a)
        person2.addChild(name3_3);
        //input
        var input1_1 = createTextFiled("", 220, 612, 36, 0x54734a, "", 426, 66, "middle", false, 0xa0a0a0, true, "INPUT")
        input1_1.type = egret.TextFieldType.INPUT;
        person2.addChild(input1_1);
        var input2_2 = createTextFiled("", 220, 702, 36, 0x54734a, "", 285, 66, "middle", false, 0xa0a0a0, true, "INPUT")
        input2_2.type = egret.TextFieldType.INPUT;
        person2.addChild(input2_2);
        var input3_3 = createTextFiled("", 255, 800, 36, 0x54734a, "", 400, 66, "middle", false, 0xa0a0a0, true, "INPUT")
        input3_3.type = egret.TextFieldType.INPUT;
        person2.addChild(input3_3);
        //input_border
        var input_border_1 = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(220, 612, 426, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border_1.addChild(roundRect);
        person2.addChild(input_border_1);
        //
        var input_border2_2 = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(220, 702, 285, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border2_2.addChild(roundRect);
        person2.addChild(input_border2_2);
        //
        var input_border2_3 = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(255, 800, 400, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border2_3.addChild(roundRect);
        person2.addChild(input_border2_3);

        //早

        //验证码倒计时
        var input_border4 = new egret.DisplayObjectContainer();
        var roundRect = new egret.Shape();
        roundRect.graphics.beginFill(0x7b7b7b)
        roundRect.graphics.lineStyle(2, 0xa0a0a0);
        roundRect.graphics.drawRoundRect(525, 702, 120, 66, 30, 30);
        roundRect.graphics.endFill();
        input_border4.addChild(roundRect);
        person2.addChild(input_border4);
        //
        var yanzhen = createTextFiled("倒计时 ：", 540, 714, 25, 0x000000)
        input_border4.addChild(yanzhen);
        var yanzhen = createTextFiled("60S ", 566, 738, 25, 0x000000)
        input_border4.addChild(yanzhen);
        //点击抽奖
        var choujiang_btn9 = createBitmap("four_btnpink_png", 280, 1030);
        person2.addChild(choujiang_btn9)
        var choujiang = createTextFiled("抽奖", 346, 1046, 36, 0xfffffff)
        choujiang.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            SenceManage.create(this.stage).loadSence("HomePageUI", null, HomePageUI);
            person2.visible = false;
        }, this)
        person2.addChild(choujiang);
        //暂时隐藏资料二
        person2.visible = false;
        // this.removeChild(person2)

        //游戏结束，未超分
        var game_over = div(0, 0, 750, 0, 750, 1206, 750, 0, 1206, 0, 0, 0);
        this.addChild(game_over);
        var personBG2 = createBitmap("four_bgimg_png", 18, 342);
        game_over.addChild(personBG2);
        var fenxiang = createBitmap("seven_share_png", 530, 34);
        game_over.addChild(fenxiang);
        var person_title = createBitmap("liuzi_tiitle_png", 85, 222);
        game_over.addChild(person_title);
        var choujiang_btn2 = createBitmap("four_btnpink_png", 280, 1030);
        game_over.addChild(choujiang_btn2);

        var choujiang2 = createTextFiled("继续游戏", 314, 1046, 36, 0xfffffff)
        choujiang2.touchEnabled = true;
        choujiang2.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            choujiang2.touchEnabled = false;
            SenceManage.create(this.stage).loadSence("GameUI", null, GameUI);
                        egret.Tween.get(this).to({x:-640},500);

        }, this)
        game_over.addChild(choujiang2);

        var choujiang3 = createTextFiled("游戏结束", 244, 620, 72, 0x54734a)
        game_over.addChild(choujiang3);
        game_over.visible = false;
        //留资页结束



        //超过分数抽奖按钮跳转老虎机
        choujiang_btn.touchEnabled = true;
        choujiang_btn.addEventListener(egret.TouchEvent.TOUCH_TAP, function () {
            SenceManage.create(this.stage).loadSence("HomePageUI", null, HomePageUI)
        }, this);
        //倒计时
        if (this.gameStatus == 1) {
            this.countdownCurNumber -=  this.frameTime;
            if (this.countdownCurNumber <= 0) {
                this.countdownCurNumber = 0;
                this.gameStatus = 0;
                console.log(this.countdownCurNumber)
               
            }
            this.countdownSprite.text = this.countdownCurNumber.toFixed(2);
        } else {
            for(let i=0;i<this.allGift.length;i++){
                console.log(this.allGift[i]);
                 egret.Tween.get(this.allGift[i]).to({visible:false},50);  
            }
            
            this.timer.stop();
            this.removeEventListener(egret.Event.ENTER_FRAME, this.loop, this);
            if (this.score >= 600) {//分数判断显示界面
                egret.Tween.get(explain).to({ visible: true }, 200);
            } else {
                egret.Tween.get(again).to({ visible: true });
            }
        }
    }
}
